<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Storable - persistence for Perl data structures - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/Storable">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="Storable.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/Storable">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/Storable">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/Storable">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/Storable">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/Storable">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/Storable">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/Storable">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/Storable">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/Storable">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/Storable">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/Storable">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/Storable">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/Storable">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/Storable">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/Storable">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/Storable">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/Storable">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/Storable">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/Storable">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/Storable">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/Storable">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/Storable">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/Storable">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/Storable">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/Storable">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/Storable">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/Storable">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/Storable">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/Storable">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/Storable">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/Storable">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/Storable">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/Storable">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/Storable">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/Storable">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/Storable">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/Storable">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/Storable">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/Storable">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/Storable">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/Storable">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/Storable">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/Storable">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/Storable">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/Storable">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/Storable">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/Storable">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/Storable">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/Storable">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/Storable">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/Storable">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/Storable">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/Storable">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/Storable">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/Storable">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/Storable">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/Storable">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/Storable">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/Storable">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/Storable">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/Storable">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/Storable">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/Storable">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/Storable">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/Storable">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/Storable">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/Storable">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/Storable">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/Storable">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/Storable">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/Storable">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/Storable">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/Storable">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/Storable">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/Storable">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/Storable">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/Storable">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/Storable">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/Storable">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/Storable">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="Storable.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/Storable">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/Storable">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/Storable">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/Storable">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/Storable">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/Storable">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/Storable">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/Storable">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/Storable">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/Storable">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/Storable">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/Storable">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/Storable">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/Storable">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/Storable">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/Storable">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/Storable">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/Storable">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/Storable">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/Storable">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/Storable">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/Storable">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/Storable">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/Storable">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/Storable">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/Storable">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/Storable">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/Storable">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/Storable">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/Storable">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/Storable">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/Storable">5.35.1</a>
          <a class="dropdown-item active" href="Storable.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="Storable.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="Storable.html">Storable</a>
          <div id="more">
            (<a href="Storable.txt">source</a>,
            <a href="https://metacpan.org/pod/Storable">CPAN</a>)
          </div>
            <div id="moduleversion">version 3.23</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="Storable.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#MEMORY-STORE">MEMORY STORE</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#ADVISORY-LOCKING">ADVISORY LOCKING</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#SPEED">SPEED</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#CANONICAL-REPRESENTATION">CANONICAL REPRESENTATION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#CODE-REFERENCES">CODE REFERENCES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#FORWARD-COMPATIBILITY">FORWARD COMPATIBILITY</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#ERROR-REPORTING">ERROR REPORTING</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#WIZARDS-ONLY">WIZARDS ONLY</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="Storable.html#Hooks">Hooks</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#Predicates">Predicates</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#Recursion">Recursion</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#Deep-Cloning">Deep Cloning</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#Storable-magic">Storable magic</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#EXAMPLES">EXAMPLES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#SECURITY-WARNING">SECURITY WARNING</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#WARNING">WARNING</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#REGULAR-EXPRESSIONS">REGULAR EXPRESSIONS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#BUGS">BUGS</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="Storable.html#64-bit-data-in-perl-5.6.0-and-5.6.1">64 bit data in perl 5.6.0 and 5.6.1</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#CREDITS">CREDITS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="Storable.html#SEE-ALSO">SEE ALSO</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="Storable.html#NAME">#</a>NAME</h1>

<p>Storable - persistence for Perl data structures</p>

<h1 id="SYNOPSIS"><a class="permalink" href="Storable.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>use Storable;
store \%table, &#39;file&#39;;
$hashref = retrieve(&#39;file&#39;);

use Storable qw(nstore store_fd nstore_fd freeze thaw dclone);

# Network order
nstore \%table, &#39;file&#39;;
$hashref = retrieve(&#39;file&#39;);	# There is NO nretrieve()

# Storing to and retrieving from an already opened file
store_fd \@array, \*STDOUT;
nstore_fd \%table, \*STDOUT;
$aryref = fd_retrieve(\*SOCKET);
$hashref = fd_retrieve(\*SOCKET);

# Serializing to memory
$serialized = freeze \%table;
%table_clone = %{ thaw($serialized) };

# Deep (recursive) cloning
$cloneref = dclone($ref);

# Advisory locking
use Storable qw(lock_store lock_nstore lock_retrieve)
lock_store \%table, &#39;file&#39;;
lock_nstore \%table, &#39;file&#39;;
$hashref = lock_retrieve(&#39;file&#39;);</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="Storable.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>The Storable package brings persistence to your Perl data structures containing SCALAR, ARRAY, HASH or REF objects, i.e. anything that can be conveniently stored to disk and retrieved at a later time.</p>

<p>It can be used in the regular procedural way by calling <code>store</code> with a reference to the object to be stored, along with the file name where the image should be written.</p>

<p>The routine returns <code>undef</code> for I/O problems or other internal error, a true value otherwise. Serious errors are propagated as a <code>die</code> exception.</p>

<p>To retrieve data stored to disk, use <code>retrieve</code> with a file name. The objects stored into that file are recreated into memory for you, and a <i>reference</i> to the root object is returned. In case an I/O error occurs while reading, <code>undef</code> is returned instead. Other serious errors are propagated via <code>die</code>.</p>

<p>Since storage is performed recursively, you might want to stuff references to objects that share a lot of common data into a single array or hash table, and then store that object. That way, when you retrieve back the whole thing, the objects will continue to share what they originally shared.</p>

<p>At the cost of a slight header overhead, you may store to an already opened file descriptor using the <code>store_fd</code> routine, and retrieve from a file via <code>fd_retrieve</code>. Those names aren&#39;t imported by default, so you will have to do that explicitly if you need those routines. The file descriptor you supply must be already opened, for read if you&#39;re going to retrieve and for write if you wish to store.</p>

<pre><code>store_fd(\%table, *STDOUT) || die &quot;can&#39;t store to stdout\n&quot;;
$hashref = fd_retrieve(*STDIN);</code></pre>

<p>You can also store data in network order to allow easy sharing across multiple platforms, or when storing on a socket known to be remotely connected. The routines to call have an initial <code>n</code> prefix for <i>network</i>, as in <code>nstore</code> and <code>nstore_fd</code>. At retrieval time, your data will be correctly restored so you don&#39;t have to know whether you&#39;re restoring from native or network ordered data. Double values are stored stringified to ensure portability as well, at the slight risk of loosing some precision in the last decimals.</p>

<p>When using <code>fd_retrieve</code>, objects are retrieved in sequence, one object (i.e. one recursive tree) per associated <code>store_fd</code>.</p>

<p>If you&#39;re more from the object-oriented camp, you can inherit from Storable and directly store your objects by invoking <code>store</code> as a method. The fact that the root of the to-be-stored tree is a blessed reference (i.e. an object) is special-cased so that the retrieve does not provide a reference to that object but rather the blessed object reference itself. (Otherwise, you&#39;d get a reference to that blessed object).</p>

<h1 id="MEMORY-STORE"><a class="permalink" href="Storable.html#MEMORY-STORE">#</a><a id="MEMORY"></a>MEMORY STORE</h1>

<p>The Storable engine can also store data into a Perl scalar instead, to later retrieve them. This is mainly used to freeze a complex structure in some safe compact memory place (where it can possibly be sent to another process via some IPC, since freezing the structure also serializes it in effect). Later on, and maybe somewhere else, you can thaw the Perl scalar out and recreate the original complex structure in memory.</p>

<p>Surprisingly, the routines to be called are named <code>freeze</code> and <code>thaw</code>. If you wish to send out the frozen scalar to another machine, use <code>nfreeze</code> instead to get a portable image.</p>

<p>Note that freezing an object structure and immediately thawing it actually achieves a deep cloning of that structure:</p>

<pre><code class="plaintext">dclone(.) = thaw(freeze(.))</code></pre>

<p>Storable provides you with a <code>dclone</code> interface which does not create that intermediary scalar but instead freezes the structure in some internal memory space and then immediately thaws it out.</p>

<h1 id="ADVISORY-LOCKING"><a class="permalink" href="Storable.html#ADVISORY-LOCKING">#</a><a id="ADVISORY"></a>ADVISORY LOCKING</h1>

<p>The <code>lock_store</code> and <code>lock_nstore</code> routine are equivalent to <code>store</code> and <code>nstore</code>, except that they get an exclusive lock on the file before writing. Likewise, <code>lock_retrieve</code> does the same as <code>retrieve</code>, but also gets a shared lock on the file before reading.</p>

<p>As with any advisory locking scheme, the protection only works if you systematically use <code>lock_store</code> and <code>lock_retrieve</code>. If one side of your application uses <code>store</code> whilst the other uses <code>lock_retrieve</code>, you will get no protection at all.</p>

<p>The internal advisory locking is implemented using Perl&#39;s flock() routine. If your system does not support any form of flock(), or if you share your files across NFS, you might wish to use other forms of locking by using modules such as LockFile::Simple which lock a file using a filesystem entry, instead of locking the file descriptor.</p>

<h1 id="SPEED"><a class="permalink" href="Storable.html#SPEED">#</a>SPEED</h1>

<p>The heart of Storable is written in C for decent speed. Extra low-level optimizations have been made when manipulating perl internals, to sacrifice encapsulation for the benefit of greater speed.</p>

<h1 id="CANONICAL-REPRESENTATION"><a class="permalink" href="Storable.html#CANONICAL-REPRESENTATION">#</a><a id="CANONICAL"></a>CANONICAL REPRESENTATION</h1>

<p>Normally, Storable stores elements of hashes in the order they are stored internally by Perl, i.e. pseudo-randomly. If you set <code>$Storable::canonical</code> to some <code>TRUE</code> value, Storable will store hashes with the elements sorted by their key. This allows you to compare data structures by comparing their frozen representations (or even the compressed frozen representations), which can be useful for creating lookup tables for complicated queries.</p>

<p>Canonical order does not imply network order; those are two orthogonal settings.</p>

<h1 id="CODE-REFERENCES"><a class="permalink" href="Storable.html#CODE-REFERENCES">#</a><a id="CODE"></a>CODE REFERENCES</h1>

<p>Since Storable version 2.05, CODE references may be serialized with the help of <a href="./B::Deparse.html">B::Deparse</a>. To enable this feature, set <code>$Storable::Deparse</code> to a true value. To enable deserialization, <code>$Storable::Eval</code> should be set to a true value. Be aware that deserialization is done through <code>eval</code>, which is dangerous if the Storable file contains malicious data. You can set <code>$Storable::Eval</code> to a subroutine reference which would be used instead of <code>eval</code>. See below for an example using a <a href="Safe.html">Safe</a> compartment for deserialization of CODE references.</p>

<p>If <code>$Storable::Deparse</code> and/or <code>$Storable::Eval</code> are set to false values, then the value of <code>$Storable::forgive_me</code> (see below) is respected while serializing and deserializing.</p>

<h1 id="FORWARD-COMPATIBILITY"><a class="permalink" href="Storable.html#FORWARD-COMPATIBILITY">#</a><a id="FORWARD"></a>FORWARD COMPATIBILITY</h1>

<p>This release of Storable can be used on a newer version of Perl to serialize data which is not supported by earlier Perls. By default, Storable will attempt to do the right thing, by <code>croak()</code>ing if it encounters data that it cannot deserialize. However, the defaults can be changed as follows:</p>

<dl>

<dt id="utf8-data"><a class="permalink" href="Storable.html#utf8-data">#</a><a id="utf8"></a>utf8 data</dt>
<dd>

<p>Perl 5.6 added support for Unicode characters with code points &gt; 255, and Perl 5.8 has full support for Unicode characters in hash keys. Perl internally encodes strings with these characters using utf8, and Storable serializes them as utf8. By default, if an older version of Perl encounters a utf8 value it cannot represent, it will <code>croak()</code>. To change this behaviour so that Storable deserializes utf8 encoded values as the string of bytes (effectively dropping the <i>is_utf8</i> flag) set <code>$Storable::drop_utf8</code> to some <code>TRUE</code> value. This is a form of data loss, because with <code>$drop_utf8</code> true, it becomes impossible to tell whether the original data was the Unicode string, or a series of bytes that happen to be valid utf8.</p>

</dd>
<dt id="restricted-hashes"><a class="permalink" href="Storable.html#restricted-hashes">#</a><a id="restricted"></a>restricted hashes</dt>
<dd>

<p>Perl 5.8 adds support for restricted hashes, which have keys restricted to a given set, and can have values locked to be read only. By default, when Storable encounters a restricted hash on a perl that doesn&#39;t support them, it will deserialize it as a normal hash, silently discarding any placeholder keys and leaving the keys and all values unlocked. To make Storable <code>croak()</code> instead, set <code>$Storable::downgrade_restricted</code> to a <code>FALSE</code> value. To restore the default set it back to some <code>TRUE</code> value.</p>

<p>The cperl PERL_PERTURB_KEYS_TOP hash strategy has a known problem with restricted hashes.</p>

</dd>
<dt id="huge-objects"><a class="permalink" href="Storable.html#huge-objects">#</a><a id="huge"></a>huge objects</dt>
<dd>

<p>On 64bit systems some data structures may exceed the 2G (i.e. I32_MAX) limit. On 32bit systems also strings between I32 and U32 (2G-4G). Since Storable 3.00 (not in perl5 core) we are able to store and retrieve these objects, even if perl5 itself is not able to handle them. These are strings longer then 4G, arrays with more then 2G elements and hashes with more then 2G elements. cperl forbids hashes with more than 2G elements, but this fail in cperl then. perl5 itself at least until 5.26 allows it, but cannot iterate over them. Note that creating those objects might cause out of memory exceptions by the operating system before perl has a chance to abort.</p>

</dd>
<dt id="files-from-future-versions-of-Storable"><a class="permalink" href="Storable.html#files-from-future-versions-of-Storable">#</a><a id="files"></a>files from future versions of Storable</dt>
<dd>

<p>Earlier versions of Storable would immediately croak if they encountered a file with a higher internal version number than the reading Storable knew about. Internal version numbers are increased each time new data types (such as restricted hashes) are added to the vocabulary of the file format. This meant that a newer Storable module had no way of writing a file readable by an older Storable, even if the writer didn&#39;t store newer data types.</p>

<p>This version of Storable will defer croaking until it encounters a data type in the file that it does not recognize. This means that it will continue to read files generated by newer Storable modules which are careful in what they write out, making it easier to upgrade Storable modules in a mixed environment.</p>

<p>The old behaviour of immediate croaking can be re-instated by setting <code>$Storable::accept_future_minor</code> to some <code>FALSE</code> value.</p>

</dd>
</dl>

<p>All these variables have no effect on a newer Perl which supports the relevant feature.</p>

<h1 id="ERROR-REPORTING"><a class="permalink" href="Storable.html#ERROR-REPORTING">#</a><a id="ERROR"></a>ERROR REPORTING</h1>

<p>Storable uses the &quot;exception&quot; paradigm, in that it does not try to workaround failures: if something bad happens, an exception is generated from the caller&#39;s perspective (see <a href="Carp.html">Carp</a> and <code>croak()</code>). Use eval {} to trap those exceptions.</p>

<p>When Storable croaks, it tries to report the error via the <code>logcroak()</code> routine from the <code>Log::Agent</code> package, if it is available.</p>

<p>Normal errors are reported by having store() or retrieve() return <code>undef</code>. Such errors are usually I/O errors (or truncated stream errors at retrieval).</p>

<p>When Storable throws the &quot;Max. recursion depth with nested structures exceeded&quot; error we are already out of stack space. Unfortunately on some earlier perl versions cleaning up a recursive data structure recurses into the free calls, which will lead to stack overflows in the cleanup. This data structure is not properly cleaned up then, it will only be destroyed during global destruction.</p>

<h1 id="WIZARDS-ONLY"><a class="permalink" href="Storable.html#WIZARDS-ONLY">#</a><a id="WIZARDS"></a>WIZARDS ONLY</h1>

<h2 id="Hooks"><a class="permalink" href="Storable.html#Hooks">#</a>Hooks</h2>

<p>Any class may define hooks that will be called during the serialization and deserialization process on objects that are instances of that class. Those hooks can redefine the way serialization is performed (and therefore, how the symmetrical deserialization should be conducted).</p>

<p>Since we said earlier:</p>

<pre><code class="plaintext">dclone(.) = thaw(freeze(.))</code></pre>

<p>everything we say about hooks should also hold for deep cloning. However, hooks get to know whether the operation is a mere serialization, or a cloning.</p>

<p>Therefore, when serializing hooks are involved,</p>

<pre><code class="plaintext">dclone(.) &lt;&gt; thaw(freeze(.))</code></pre>

<p>Well, you could keep them in sync, but there&#39;s no guarantee it will always hold on classes somebody else wrote. Besides, there is little to gain in doing so: a serializing hook could keep only one attribute of an object, which is probably not what should happen during a deep cloning of that same object.</p>

<p>Here is the hooking interface:</p>

<dl>

<dt id="STORABLE_freeze-obj,-cloning"><a class="permalink" href="Storable.html#STORABLE_freeze-obj,-cloning">#</a><a id="STORABLE_freeze"></a><a id="STORABLE_freeze-obj-cloning"></a><code>STORABLE_freeze</code> <i>obj</i>, <i>cloning</i></dt>
<dd>

<p>The serializing hook, called on the object during serialization. It can be inherited, or defined in the class itself, like any other method.</p>

<p>Arguments: <i>obj</i> is the object to serialize, <i>cloning</i> is a flag indicating whether we&#39;re in a dclone() or a regular serialization via store() or freeze().</p>

<p>Returned value: A LIST <code>($serialized, $ref1, $ref2, ...)</code> where $serialized is the serialized form to be used, and the optional $ref1, $ref2, etc... are extra references that you wish to let the Storable engine serialize.</p>

<p>At deserialization time, you will be given back the same LIST, but all the extra references will be pointing into the deserialized structure.</p>

<p>The <b>first time</b> the hook is hit in a serialization flow, you may have it return an empty list. That will signal the Storable engine to further discard that hook for this class and to therefore revert to the default serialization of the underlying Perl data. The hook will again be normally processed in the next serialization.</p>

<p>Unless you know better, serializing hook should always say:</p>

<pre><code>sub STORABLE_freeze {
    my ($self, $cloning) = @_;
    return if $cloning;         # Regular default serialization
    ....
}</code></pre>

<p>in order to keep reasonable dclone() semantics.</p>

</dd>
<dt id="STORABLE_thaw-obj,-cloning,-serialized,-..."><a class="permalink" href="Storable.html#STORABLE_thaw-obj,-cloning,-serialized,-...">#</a><a id="STORABLE_thaw"></a><a id="STORABLE_thaw-obj-cloning-serialized"></a><code>STORABLE_thaw</code> <i>obj</i>, <i>cloning</i>, <i>serialized</i>, ...</dt>
<dd>

<p>The deserializing hook called on the object during deserialization. But wait: if we&#39;re deserializing, there&#39;s no object yet... right?</p>

<p>Wrong: the Storable engine creates an empty one for you. If you know Eiffel, you can view <code>STORABLE_thaw</code> as an alternate creation routine.</p>

<p>This means the hook can be inherited like any other method, and that <i>obj</i> is your blessed reference for this particular instance.</p>

<p>The other arguments should look familiar if you know <code>STORABLE_freeze</code>: <i>cloning</i> is true when we&#39;re part of a deep clone operation, <i>serialized</i> is the serialized string you returned to the engine in <code>STORABLE_freeze</code>, and there may be an optional list of references, in the same order you gave them at serialization time, pointing to the deserialized objects (which have been processed courtesy of the Storable engine).</p>

<p>When the Storable engine does not find any <code>STORABLE_thaw</code> hook routine, it tries to load the class by requiring the package dynamically (using the blessed package name), and then re-attempts the lookup. If at that time the hook cannot be located, the engine croaks. Note that this mechanism will fail if you define several classes in the same file, but <a href="perlmod.html">perlmod</a> warned you.</p>

<p>It is up to you to use this information to populate <i>obj</i> the way you want.</p>

<p>Returned value: none.</p>

</dd>
<dt id="STORABLE_attach-class,-cloning,-serialized"><a class="permalink" href="Storable.html#STORABLE_attach-class,-cloning,-serialized">#</a><a id="STORABLE_attach"></a><a id="STORABLE_attach-class-cloning-serialized"></a><code>STORABLE_attach</code> <i>class</i>, <i>cloning</i>, <i>serialized</i></dt>
<dd>

<p>While <code>STORABLE_freeze</code> and <code>STORABLE_thaw</code> are useful for classes where each instance is independent, this mechanism has difficulty (or is incompatible) with objects that exist as common process-level or system-level resources, such as singleton objects, database pools, caches or memoized objects.</p>

<p>The alternative <code>STORABLE_attach</code> method provides a solution for these shared objects. Instead of <code>STORABLE_freeze</code> --&gt; <code>STORABLE_thaw</code>, you implement <code>STORABLE_freeze</code> --&gt; <code>STORABLE_attach</code> instead.</p>

<p>Arguments: <i>class</i> is the class we are attaching to, <i>cloning</i> is a flag indicating whether we&#39;re in a dclone() or a regular de-serialization via thaw(), and <i>serialized</i> is the stored string for the resource object.</p>

<p>Because these resource objects are considered to be owned by the entire process/system, and not the &quot;property&quot; of whatever is being serialized, no references underneath the object should be included in the serialized string. Thus, in any class that implements <code>STORABLE_attach</code>, the <code>STORABLE_freeze</code> method cannot return any references, and <code>Storable</code> will throw an error if <code>STORABLE_freeze</code> tries to return references.</p>

<p>All information required to &quot;attach&quot; back to the shared resource object <b>must</b> be contained <b>only</b> in the <code>STORABLE_freeze</code> return string. Otherwise, <code>STORABLE_freeze</code> behaves as normal for <code>STORABLE_attach</code> classes.</p>

<p>Because <code>STORABLE_attach</code> is passed the class (rather than an object), it also returns the object directly, rather than modifying the passed object.</p>

<p>Returned value: object of type <code>class</code></p>

</dd>
</dl>

<h2 id="Predicates"><a class="permalink" href="Storable.html#Predicates">#</a>Predicates</h2>

<p>Predicates are not exportable. They must be called by explicitly prefixing them with the Storable package name.</p>

<dl>

<dt id="Storable::last_op_in_netorder"><a class="permalink" href="Storable.html#Storable::last_op_in_netorder">#</a><a id="Storable"></a><code>Storable::last_op_in_netorder</code></dt>
<dd>

<p>The <code>Storable::last_op_in_netorder()</code> predicate will tell you whether network order was used in the last store or retrieve operation. If you don&#39;t know how to use this, just forget about it.</p>

</dd>
<dt id="Storable::is_storing"><a class="permalink" href="Storable.html#Storable::is_storing">#</a><a id="Storable1"></a><code>Storable::is_storing</code></dt>
<dd>

<p>Returns true if within a store operation (via STORABLE_freeze hook).</p>

</dd>
<dt id="Storable::is_retrieving"><a class="permalink" href="Storable.html#Storable::is_retrieving">#</a><a id="Storable2"></a><code>Storable::is_retrieving</code></dt>
<dd>

<p>Returns true if within a retrieve operation (via STORABLE_thaw hook).</p>

</dd>
</dl>

<h2 id="Recursion"><a class="permalink" href="Storable.html#Recursion">#</a>Recursion</h2>

<p>With hooks comes the ability to recurse back to the Storable engine. Indeed, hooks are regular Perl code, and Storable is convenient when it comes to serializing and deserializing things, so why not use it to handle the serialization string?</p>

<p>There are a few things you need to know, however:</p>

<ul>

<li><p>From Storable 3.05 to 3.13 we probed for the stack recursion limit for references, arrays and hashes to a maximal depth of ~1200-35000, otherwise we might fall into a stack-overflow. On JSON::XS this limit is 512 btw. With references not immediately referencing each other there&#39;s no such limit yet, so you might fall into such a stack-overflow segfault.</p>

<p>This probing and the checks we performed have some limitations:</p>

<ul>

<li><p>the stack size at build time might be different at run time, eg. the stack size may have been modified with ulimit(1). If it&#39;s larger at run time Storable may fail the freeze() or thaw() unnecessarily. If it&#39;s larger at build time Storable may segmentation fault when processing a deep structure at run time.</p>

</li>
<li><p>the stack size might be different in a thread.</p>

</li>
<li><p>array and hash recursion limits are checked separately against the same recursion depth, a frozen structure with a large sequence of nested arrays within many nested hashes may exhaust the processor stack without triggering Storable&#39;s recursion protection.</p>

</li>
</ul>

<p>So these now have simple defaults rather than probing at build-time.</p>

<p>You can control the maximum array and hash recursion depths by modifying <code>$Storable::recursion_limit</code> and <code>$Storable::recursion_limit_hash</code> respectively. Either can be set to <code>-1</code> to prevent any depth checks, though this isn&#39;t recommended.</p>

<p>If you want to test what the limits are, the <i>stacksize</i> tool is included in the <code>Storable</code> distribution.</p>

</li>
<li><p>You can create endless loops if the things you serialize via freeze() (for instance) point back to the object we&#39;re trying to serialize in the hook.</p>

</li>
<li><p>Shared references among objects will not stay shared: if we&#39;re serializing the list of object [A, C] where both object A and C refer to the SAME object B, and if there is a serializing hook in A that says freeze(B), then when deserializing, we&#39;ll get [A&#39;, C&#39;] where A&#39; refers to B&#39;, but C&#39; refers to D, a deep clone of B&#39;. The topology was not preserved.</p>

</li>
<li><p>The maximal stack recursion limit for your system is returned by <code>stack_depth()</code> and <code>stack_depth_hash()</code>. The hash limit is usually half the size of the array and ref limit, as the Perl hash API is not optimal.</p>

</li>
</ul>

<p>That&#39;s why <code>STORABLE_freeze</code> lets you provide a list of references to serialize. The engine guarantees that those will be serialized in the same context as the other objects, and therefore that shared objects will stay shared.</p>

<p>In the above [A, C] example, the <code>STORABLE_freeze</code> hook could return:</p>

<pre><code>(&quot;something&quot;, $self-&gt;{B})</code></pre>

<p>and the B part would be serialized by the engine. In <code>STORABLE_thaw</code>, you would get back the reference to the B&#39; object, deserialized for you.</p>

<p>Therefore, recursion should normally be avoided, but is nonetheless supported.</p>

<h2 id="Deep-Cloning"><a class="permalink" href="Storable.html#Deep-Cloning">#</a><a id="Deep"></a>Deep Cloning</h2>

<p>There is a Clone module available on CPAN which implements deep cloning natively, i.e. without freezing to memory and thawing the result. It is aimed to replace Storable&#39;s dclone() some day. However, it does not currently support Storable hooks to redefine the way deep cloning is performed.</p>

<h1 id="Storable-magic"><a class="permalink" href="Storable.html#Storable-magic">#</a><a id="Storable3"></a>Storable magic</h1>

<p>Yes, there&#39;s a lot of that :-) But more precisely, in UNIX systems there&#39;s a utility called <code>file</code>, which recognizes data files based on their contents (usually their first few bytes). For this to work, a certain file called <i>magic</i> needs to taught about the <i>signature</i> of the data. Where that configuration file lives depends on the UNIX flavour; often it&#39;s something like <i>/usr/share/misc/magic</i> or <i>/etc/magic</i>. Your system administrator needs to do the updating of the <i>magic</i> file. The necessary signature information is output to STDOUT by invoking Storable::show_file_magic(). Note that the GNU implementation of the <code>file</code> utility, version 3.38 or later, is expected to contain support for recognising Storable files out-of-the-box, in addition to other kinds of Perl files.</p>

<p>You can also use the following functions to extract the file header information from Storable images:</p>

<dl>

<dt id="$info-=-Storable::file_magic(-$filename-)"><a class="permalink" href="Storable.html#$info-=-Storable::file_magic(-$filename-)">#</a><a id="info-Storable::file_magic-filename"></a>$info = Storable::file_magic( $filename )</dt>
<dd>

<p>If the given file is a Storable image return a hash describing it. If the file is readable, but not a Storable image return <code>undef</code>. If the file does not exist or is unreadable then croak.</p>

<p>The hash returned has the following elements:</p>

<dl>

<dt id="version"><a class="permalink" href="Storable.html#version">#</a><code>version</code></dt>
<dd>

<p>This returns the file format version. It is a string like &quot;2.7&quot;.</p>

<p>Note that this version number is not the same as the version number of the Storable module itself. For instance Storable v0.7 create files in format v2.0 and Storable v2.15 create files in format v2.7. The file format version number only increment when additional features that would confuse older versions of the module are added.</p>

<p>Files older than v2.0 will have the one of the version numbers &quot;-1&quot;, &quot;0&quot; or &quot;1&quot;. No minor number was used at that time.</p>

</dd>
<dt id="version_nv"><a class="permalink" href="Storable.html#version_nv">#</a><code>version_nv</code></dt>
<dd>

<p>This returns the file format version as number. It is a string like &quot;2.007&quot;. This value is suitable for numeric comparisons.</p>

<p>The constant function <code>Storable::BIN_VERSION_NV</code> returns a comparable number that represents the highest file version number that this version of Storable fully supports (but see discussion of <code>$Storable::accept_future_minor</code> above). The constant <code>Storable::BIN_WRITE_VERSION_NV</code> function returns what file version is written and might be less than <code>Storable::BIN_VERSION_NV</code> in some configurations.</p>

</dd>
<dt id="major,-minor"><a class="permalink" href="Storable.html#major,-minor">#</a><a id="major"></a><a id="major-minor"></a><code>major</code>, <code>minor</code></dt>
<dd>

<p>This also returns the file format version. If the version is &quot;2.7&quot; then major would be 2 and minor would be 7. The minor element is missing for when major is less than 2.</p>

</dd>
<dt id="hdrsize"><a class="permalink" href="Storable.html#hdrsize">#</a><code>hdrsize</code></dt>
<dd>

<p>The is the number of bytes that the Storable header occupies.</p>

</dd>
<dt id="netorder"><a class="permalink" href="Storable.html#netorder">#</a><code>netorder</code></dt>
<dd>

<p>This is TRUE if the image store data in network order. This means that it was created with nstore() or similar.</p>

</dd>
<dt id="byteorder"><a class="permalink" href="Storable.html#byteorder">#</a><code>byteorder</code></dt>
<dd>

<p>This is only present when <code>netorder</code> is FALSE. It is the $Config{byteorder} string of the perl that created this image. It is a string like &quot;1234&quot; (32 bit little endian) or &quot;87654321&quot; (64 bit big endian). This must match the current perl for the image to be readable by Storable.</p>

</dd>
<dt id="intsize,-longsize,-ptrsize,-nvsize"><a class="permalink" href="Storable.html#intsize,-longsize,-ptrsize,-nvsize">#</a><a id="intsize"></a><a id="intsize-longsize-ptrsize-nvsize"></a><code>intsize</code>, <code>longsize</code>, <code>ptrsize</code>, <code>nvsize</code></dt>
<dd>

<p>These are only present when <code>netorder</code> is FALSE. These are the sizes of various C datatypes of the perl that created this image. These must match the current perl for the image to be readable by Storable.</p>

<p>The <code>nvsize</code> element is only present for file format v2.2 and higher.</p>

</dd>
<dt id="file"><a class="permalink" href="Storable.html#file">#</a><code>file</code></dt>
<dd>

<p>The name of the file.</p>

</dd>
</dl>

</dd>
<dt id="$info-=-Storable::read_magic(-$buffer-)"><a class="permalink" href="Storable.html#$info-=-Storable::read_magic(-$buffer-)">#</a><a id="info-Storable::read_magic-buffer"></a>$info = Storable::read_magic( $buffer )</dt>
<dd>

</dd>
<dt id="$info-=-Storable::read_magic(-$buffer,-$must_be_file-)"><a class="permalink" href="Storable.html#$info-=-Storable::read_magic(-$buffer,-$must_be_file-)">#</a><a id="info-Storable::read_magic-buffer-must_be_file"></a>$info = Storable::read_magic( $buffer, $must_be_file )</dt>
<dd>

<p>The $buffer should be a Storable image or the first few bytes of it. If $buffer starts with a Storable header, then a hash describing the image is returned, otherwise <code>undef</code> is returned.</p>

<p>The hash has the same structure as the one returned by Storable::file_magic(). The <code>file</code> element is true if the image is a file image.</p>

<p>If the $must_be_file argument is provided and is TRUE, then return <code>undef</code> unless the image looks like it belongs to a file dump.</p>

<p>The maximum size of a Storable header is currently 21 bytes. If the provided $buffer is only the first part of a Storable image it should at least be this long to ensure that read_magic() will recognize it as such.</p>

</dd>
</dl>

<h1 id="EXAMPLES"><a class="permalink" href="Storable.html#EXAMPLES">#</a>EXAMPLES</h1>

<p>Here are some code samples showing a possible usage of Storable:</p>

<pre><code>use Storable qw(store retrieve freeze thaw dclone);

%color = (&#39;Blue&#39; =&gt; 0.1, &#39;Red&#39; =&gt; 0.8, &#39;Black&#39; =&gt; 0, &#39;White&#39; =&gt; 1);

store(\%color, &#39;mycolors&#39;) or die &quot;Can&#39;t store %a in mycolors!\n&quot;;

$colref = retrieve(&#39;mycolors&#39;);
die &quot;Unable to retrieve from mycolors!\n&quot; unless defined $colref;
printf &quot;Blue is still %lf\n&quot;, $colref-&gt;{&#39;Blue&#39;};

$colref2 = dclone(\%color);

$str = freeze(\%color);
printf &quot;Serialization of %%color is %d bytes long.\n&quot;, length($str);
$colref3 = thaw($str);</code></pre>

<p>which prints (on my machine):</p>

<pre><code>Blue is still 0.100000
Serialization of %color is 102 bytes long.</code></pre>

<p>Serialization of CODE references and deserialization in a safe compartment:</p>

<pre><code>use Storable qw(freeze thaw);
use Safe;
use strict;
my $safe = new Safe;
       # because of opcodes used in &quot;use strict&quot;:
$safe-&gt;permit(qw(:default require));
local $Storable::Deparse = 1;
local $Storable::Eval = sub { $safe-&gt;reval($_[0]) };
my $serialized = freeze(sub { 42 });
my $code = thaw($serialized);
$code-&gt;() == 42;</code></pre>

<h1 id="SECURITY-WARNING"><a class="permalink" href="Storable.html#SECURITY-WARNING">#</a><a id="SECURITY"></a>SECURITY WARNING</h1>

<p><b>Do not accept Storable documents from untrusted sources!</b></p>

<p>Some features of Storable can lead to security vulnerabilities if you accept Storable documents from untrusted sources with the default flags. Most obviously, the optional (off by default) CODE reference serialization feature allows transfer of code to the deserializing process. Furthermore, any serialized object will cause Storable to helpfully load the module corresponding to the class of the object in the deserializing module. For manipulated module names, this can load almost arbitrary code. Finally, the deserialized object&#39;s destructors will be invoked when the objects get destroyed in the deserializing process. Maliciously crafted Storable documents may put such objects in the value of a hash key that is overridden by another key/value pair in the same hash, thus causing immediate destructor execution.</p>

<p>To disable blessing objects while thawing/retrieving remove the flag <code>BLESS_OK</code> = 2 from <code>$Storable::flags</code> or set the 2nd argument for thaw/retrieve to 0.</p>

<p>To disable tieing data while thawing/retrieving remove the flag <code>TIE_OK</code> = 4 from <code>$Storable::flags</code> or set the 2nd argument for thaw/retrieve to 0.</p>

<p>With the default setting of <code>$Storable::flags</code> = 6, creating or destroying random objects, even renamed objects can be controlled by an attacker. See CVE-2015-1592 and its metasploit module.</p>

<p>If your application requires accepting data from untrusted sources, you are best off with a less powerful and more-likely safe serialization format and implementation. If your data is sufficiently simple, <a href="./Cpanel::JSON::XS.html">Cpanel::JSON::XS</a>, <a href="./Data::MessagePack.html">Data::MessagePack</a> or <a href="Sereal.html">Sereal</a> are the best choices and offer maximum interoperability, but note that Sereal is <a href="./Sereal::Decoder.html#ROBUSTNESS">unsafe by default</a>.</p>

<h1 id="WARNING"><a class="permalink" href="Storable.html#WARNING">#</a>WARNING</h1>

<p>If you&#39;re using references as keys within your hash tables, you&#39;re bound to be disappointed when retrieving your data. Indeed, Perl stringifies references used as hash table keys. If you later wish to access the items via another reference stringification (i.e. using the same reference that was used for the key originally to record the value into the hash table), it will work because both references stringify to the same string.</p>

<p>It won&#39;t work across a sequence of <code>store</code> and <code>retrieve</code> operations, however, because the addresses in the retrieved objects, which are part of the stringified references, will probably differ from the original addresses. The topology of your structure is preserved, but not hidden semantics like those.</p>

<p>On platforms where it matters, be sure to call <code>binmode()</code> on the descriptors that you pass to Storable functions.</p>

<p>Storing data canonically that contains large hashes can be significantly slower than storing the same data normally, as temporary arrays to hold the keys for each hash have to be allocated, populated, sorted and freed. Some tests have shown a halving of the speed of storing -- the exact penalty will depend on the complexity of your data. There is no slowdown on retrieval.</p>

<h1 id="REGULAR-EXPRESSIONS"><a class="permalink" href="Storable.html#REGULAR-EXPRESSIONS">#</a><a id="REGULAR"></a>REGULAR EXPRESSIONS</h1>

<p>Storable now has experimental support for storing regular expressions, but there are significant limitations:</p>

<ul>

<li><p>perl 5.8 or later is required.</p>

</li>
<li><p>regular expressions with code blocks, ie <code>/(?{ ... })/</code> or <code>/(??{ ... })/</code> will throw an exception when thawed.</p>

</li>
<li><p>regular expression syntax and flags have changed over the history of perl, so a regular expression that you freeze in one version of perl may fail to thaw or behave differently in another version of perl.</p>

</li>
<li><p>depending on the version of perl, regular expressions can change in behaviour depending on the context, but later perls will bake that behaviour into the regexp.</p>

</li>
</ul>

<p>Storable will throw an exception if a frozen regular expression cannot be thawed.</p>

<h1 id="BUGS"><a class="permalink" href="Storable.html#BUGS">#</a>BUGS</h1>

<p>You can&#39;t store GLOB, FORMLINE, etc.... If you can define semantics for those operations, feel free to enhance Storable so that it can deal with them.</p>

<p>The store functions will <code>croak</code> if they run into such references unless you set <code>$Storable::forgive_me</code> to some <code>TRUE</code> value. In that case, the fatal message is converted to a warning and some meaningless string is stored instead.</p>

<p>Setting <code>$Storable::canonical</code> may not yield frozen strings that compare equal due to possible stringification of numbers. When the string version of a scalar exists, it is the form stored; therefore, if you happen to use your numbers as strings between two freezing operations on the same data structures, you will get different results.</p>

<p>When storing doubles in network order, their value is stored as text. However, you should also not expect non-numeric floating-point values such as infinity and &quot;not a number&quot; to pass successfully through a nstore()/retrieve() pair.</p>

<p>As Storable neither knows nor cares about character sets (although it does know that characters may be more than eight bits wide), any difference in the interpretation of character codes between a host and a target system is your problem. In particular, if host and target use different code points to represent the characters used in the text representation of floating-point numbers, you will not be able be able to exchange floating-point data, even with nstore().</p>

<p><code>Storable::drop_utf8</code> is a blunt tool. There is no facility either to return <b>all</b> strings as utf8 sequences, or to attempt to convert utf8 data back to 8 bit and <code>croak()</code> if the conversion fails.</p>

<p>Prior to Storable 2.01, no distinction was made between signed and unsigned integers on storing. By default Storable prefers to store a scalars string representation (if it has one) so this would only cause problems when storing large unsigned integers that had never been converted to string or floating point. In other words values that had been generated by integer operations such as logic ops and then not used in any string or arithmetic context before storing.</p>

<h2 id="64-bit-data-in-perl-5.6.0-and-5.6.1"><a class="permalink" href="Storable.html#64-bit-data-in-perl-5.6.0-and-5.6.1">#</a><a id="64"></a><a id="bit-data-in-perl-5.6.0-and-5.6.1"></a>64 bit data in perl 5.6.0 and 5.6.1</h2>

<p>This section only applies to you if you have existing data written out by Storable 2.02 or earlier on perl 5.6.0 or 5.6.1 on Unix or Linux which has been configured with 64 bit integer support (not the default) If you got a precompiled perl, rather than running Configure to build your own perl from source, then it almost certainly does not affect you, and you can stop reading now (unless you&#39;re curious). If you&#39;re using perl on Windows it does not affect you.</p>

<p>Storable writes a file header which contains the sizes of various C language types for the C compiler that built Storable (when not writing in network order), and will refuse to load files written by a Storable not on the same (or compatible) architecture. This check and a check on machine byteorder is needed because the size of various fields in the file are given by the sizes of the C language types, and so files written on different architectures are incompatible. This is done for increased speed. (When writing in network order, all fields are written out as standard lengths, which allows full interworking, but takes longer to read and write)</p>

<p>Perl 5.6.x introduced the ability to optional configure the perl interpreter to use C&#39;s <code>long long</code> type to allow scalars to store 64 bit integers on 32 bit systems. However, due to the way the Perl configuration system generated the C configuration files on non-Windows platforms, and the way Storable generates its header, nothing in the Storable file header reflected whether the perl writing was using 32 or 64 bit integers, despite the fact that Storable was storing some data differently in the file. Hence Storable running on perl with 64 bit integers will read the header from a file written by a 32 bit perl, not realise that the data is actually in a subtly incompatible format, and then go horribly wrong (possibly crashing) if it encountered a stored integer. This is a design failure.</p>

<p>Storable has now been changed to write out and read in a file header with information about the size of integers. It&#39;s impossible to detect whether an old file being read in was written with 32 or 64 bit integers (they have the same header) so it&#39;s impossible to automatically switch to a correct backwards compatibility mode. Hence this Storable defaults to the new, correct behaviour.</p>

<p>What this means is that if you have data written by Storable 1.x running on perl 5.6.0 or 5.6.1 configured with 64 bit integers on Unix or Linux then by default this Storable will refuse to read it, giving the error <i>Byte order is not compatible</i>. If you have such data then you should set <code>$Storable::interwork_56_64bit</code> to a true value to make this Storable read and write files with the old header. You should also migrate your data, or any older perl you are communicating with, to this current version of Storable.</p>

<p>If you don&#39;t have data written with specific configuration of perl described above, then you do not and should not do anything. Don&#39;t set the flag - not only will Storable on an identically configured perl refuse to load them, but Storable a differently configured perl will load them believing them to be correct for it, and then may well fail or crash part way through reading them.</p>

<h1 id="CREDITS"><a class="permalink" href="Storable.html#CREDITS">#</a>CREDITS</h1>

<p>Thank you to (in chronological order):</p>

<pre><code>Jarkko Hietaniemi &lt;jhi@iki.fi&gt;
Ulrich Pfeifer &lt;pfeifer@charly.informatik.uni-dortmund.de&gt;
Benjamin A. Holzman &lt;bholzman@earthlink.net&gt;
Andrew Ford &lt;A.Ford@ford-mason.co.uk&gt;
Gisle Aas &lt;gisle@aas.no&gt;
Jeff Gresham &lt;gresham_jeffrey@jpmorgan.com&gt;
Murray Nesbitt &lt;murray@activestate.com&gt;
Marc Lehmann &lt;pcg@opengroup.org&gt;
Justin Banks &lt;justinb@wamnet.com&gt;
Jarkko Hietaniemi &lt;jhi@iki.fi&gt; (AGAIN, as perl 5.7.0 Pumpkin!)
Salvador Ortiz Garcia &lt;sog@msg.com.mx&gt;
Dominic Dunlop &lt;domo@computer.org&gt;
Erik Haugan &lt;erik@solbors.no&gt;
Benjamin A. Holzman &lt;ben.holzman@grantstreet.com&gt;
Reini Urban &lt;rurban@cpan.org&gt;
Todd Rinaldo &lt;toddr@cpanel.net&gt;
Aaron Crane &lt;arc@cpan.org&gt;</code></pre>

<p>for their bug reports, suggestions and contributions.</p>

<p>Benjamin Holzman contributed the tied variable support, Andrew Ford contributed the canonical order for hashes, and Gisle Aas fixed a few misunderstandings of mine regarding the perl internals, and optimized the emission of &quot;tags&quot; in the output streams by simply counting the objects instead of tagging them (leading to a binary incompatibility for the Storable image starting at version 0.6--older images are, of course, still properly understood). Murray Nesbitt made Storable thread-safe. Marc Lehmann added overloading and references to tied items support. Benjamin Holzman added a performance improvement for overloaded classes; thanks to Grant Street Group for footing the bill. Reini Urban took over maintenance from p5p, and added security fixes and huge object support.</p>

<h1 id="AUTHOR"><a class="permalink" href="Storable.html#AUTHOR">#</a>AUTHOR</h1>

<p>Storable was written by Raphael Manfredi <i>&lt;Raphael_Manfredi@pobox.com&gt;</i> Maintenance is now done by cperl <a href="http://perl11.org/cperl">http://perl11.org/cperl</a></p>

<p>Please e-mail us with problems, bug fixes, comments and complaints, although if you have compliments you should send them to Raphael. Please don&#39;t e-mail Raphael with problems, as he no longer works on Storable, and your message will be delayed while he forwards it to us.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="Storable.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p><a href="Clone.html">Clone</a>.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
